//
//  PopStatusBarMessageView.m
//  XKStudyDemo
//
//  Created by xukai on 2017/11/30.
//  Copyright © 2017年 xukai. All rights reserved.
//

#import "PopStatusBarMessageView.h"

@implementation PopStatusBarMessageView

+(void) showMessage:(NSString *) message
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    window.windowLevel = UIWindowLevelStatusBar;// 隐藏状态栏
    UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDHT, 20)];
    showView.backgroundColor = [UIColor blueColor];
    [window addSubview:showView];
    UILabel *titleLab = [UILabel makeCommonWithFrame:CGRectMake(20, 0, showView.width - 40, showView.height) textColor:ColorFromRGB(0x151515) bgColor:nil font:12 textAlignment:NSTextAlignmentCenter title:message];
    [showView addSubview:titleLab];
    
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(delayMethodWith:) userInfo:@{@"vv" : showView} repeats:YES];
    [timer fire];
    
    [UIView animateWithDuration:0.1 delay:2 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
        showView.alpha = 0;
    } completion:^(BOOL finished) {
        [timer invalidate];
        [showView removeFromSuperview];
        window.windowLevel = UIWindowLevelNormal;// 隐藏状态栏

    }];
}

+(void) delayMethodWith:(NSTimer *) timer
{
    UIView *view = timer.userInfo[@"vv"];
    view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:0.6];
}

@end
